/** 
    ____                            
   / __ )_________ __   _____  _____
  / __  / ___/ __ `/ | / / _ \/ ___/
 / /_/ / /  / /_/ /| |/ /  __/ /    
/_____/_/   \__,_/ |___/\___/_/     
* @Title: CachLoaderFactory.java 
* @Package soft.ay.qram.helpers 
* @Description: 缓存工具获取类
* @author vsuns 
* @date 2019年6月7日 
* @version V1.0 
*/ 
package soft.ay.qram.helpers;

import java.lang.reflect.InvocationTargetException;

import soft.ay.qram.ICacheLoader;
import soft.ay.qram.SimpleSyncStringCacheLoader;

/**
 * 依据传入参数，用Loader中加载对应的CacheLoader
 */
public class CacheLoaderContext
{
    // 属性部分
    static final Class<?> DEFAULT_LOADER = SimpleSyncStringCacheLoader.class;
    //------------------分割线------------------
    // 方法部分
    public static ICacheLoader createLoader(Class<?> clazz)
    {
        ICacheLoader cacheLoader = null;

        try
        {
            if (clazz == null)
            {
                return (ICacheLoader) Loader.newCheckedInstanceOf(DEFAULT_LOADER.getName(), DEFAULT_LOADER);
                // return new SimpleSyncStringCacheLoader();
            }
            cacheLoader = (ICacheLoader) Loader.newCheckedInstanceOf(clazz.getName(), clazz);
        }
        catch (ClassNotFoundException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (NoSuchMethodException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (IllegalAccessException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (InvocationTargetException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (InstantiationException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return cacheLoader;
    }
    
}
